home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / NUMBERS.SWG / 0029_Random Number Generator.pas < prev    next >
Pascal/Delphi Source File  |  1993-09-26  |  868b  |  35 lines

  1. (*
  2. From: KENT BRIGGS                  Refer#: NONE
  3. Subj: TP 7.0 RANDOM GENERATOR        Conf: (1221) F-PASCAL
  4. *)
  5.  
  6. const
  7.   rseed: longint = 0;
  8.  
  9. procedure randomize67;      {TP 6.0 & 7.0 seed generator}
  10. begin
  11.   reg.ah:=$2c;
  12.   msdos(reg);    {get time: ch=hour,cl=min,dh=sec,dl=sec/100}
  13.   rseed:=reg.dx;
  14.   rseed:=(rseed shl 16) or reg.cx;
  15. end;
  16.  
  17. function rand_word6(x: word): word;    {TP 6.0 RNG: word}
  18. begin
  19.   rseed:=rseed*134775813+1;
  20.   rand_word6:=(rseed shr 16) mod x;
  21. end;
  22.  
  23. function rand_word7(x: word): word;    {TP 7.0 RNG: word}
  24. begin
  25.   rseed:=rseed*134775813+1;
  26.   rand_word7:=((rseed shr 16)*x+((rseed and $ffff)*x shr 16)) shr 16;
  27. end;
  28.  
  29. function rand_real67: real;    {TP 6.0 & 7.0 RNG: real}
  30. begin
  31.   rseed:=rseed*134775813+1;
  32.   if rseed<0 then rand_real67:=rseed/4294967296.0+1.0 else
  33.   rand_real67:=rseed/4294967296.0;
  34. end;
  35.